package com.cobra.controller;

import com.cobra.exception.NotEnoughMoneyException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/global")
    public String globalExceptionTest(String type) throws Exception {
        if("1".equals(type)){
            return "success";
        }else {
            throw new Exception("未获取预期的输入");
        }
    }

    @RequestMapping("/buy")
    public String buy(@RequestParam(name="money") Integer money){
        Integer account = 50;
        if(money > account){
            throw new NotEnoughMoneyException("not enough money ,rest is "+ account +" but need "+money);
        }else {
            return "success";
        }
    }

}
